import Pubsub from 'pubsub-js'
export default function(songindex,musicList){
   // 订阅song页面点击的是哪个按钮并接收到按钮信息（上一首，下一首）
   Pubsub.subscribe('switchType', (_, type) => {
   let obj ={}
    if (type === 'pre') {
      // 用户点击了上一首按钮
      if (songindex == 0) {
         obj.songindex=musicList.length - 1
      }
       obj.songindex=songindex--
      const newsongid = musicList[songindex].id
      Pubsub.publish('sendnewsongid', newsongid)
      return obj
    } else {
      // 用户点击了下一首按钮
      if (songindex == musicList.length - 1) {
          obj.songindex= 0
      }
      obj.songindex=songindex++
      const newsongid = musicList[songindex].id
      Pubsub.publish('sendnewsongid', newsongid)
      return obj
    }
  })
}